﻿using System.Runtime.Intrinsics;

namespace _03_C_中的疑惑点____Equals_ReferenceEquals
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Console.Title = "C#的等于比较";

            ////==的比较
            ////值类型的比较
            //int v1 = 1;
            //double v2 = 1;

            //Console.WriteLine($"不相同类型的值类型的==：{v1 == v2}");//true

            //引用类型的==

            //Student student1 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};

            //Student student2 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};

            //Console.WriteLine($"引用类型=={student1==student2}");//false

            //Student student3 = student1;

            //Console.WriteLine($"赋值类型的引用类型==：{student1==student3}");//true

            //-----
            //string str1 = "Hello";
            //string str2 = "Hello";
            //string str3 = "He";
            //string str4 = "llo";
            //string str5 = str3 + str4;
            //Console.WriteLine($"string类型==：{str1 == str2}");//true
            //Console.WriteLine($"string类型拼接:{str1 == str5}");//true

            //Console.WriteLine($"1和2的地址：{object.ReferenceEquals(str1, str2)}");//true
            //Console.WriteLine($"1和5的地址：{object.ReferenceEquals(str1, str5)}");//false

            //equals的比较
            //值类型的比较

            //int vl = 1;
            //int v2 = 1;

            //Console.WriteLine($"值类型的equals:{vl.Equals(v2)}");//true

            //double v3 = 1;//范围大

            //Console.WriteLine($"不同类型的值类型的equals:{vl.Equals(v3)}");//false

            //Console.WriteLine($"不同类型的值类型的equals:{v3.Equals(vl)}");//true //大类型小类型

            //引用类型
            //Student student1 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};

            //Student student2 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};
            //Console.WriteLine($"引用类型equals:{student1.Equals(student2)}");//false

            //Student student3 = student1;

            //Console.WriteLine($"赋值类型的引用类型equals：{student1.Equals(student3)}");//true

            //string类型
            //string str1 = "Hello";
            //string str2 = "Hello";

            //string str3 = "He";
            //string str4 = "llo";
            //string str5 = str3 + str4;

            //Console.WriteLine($"str1和str2的equel:{str1.Equals(str2)}");//true
            //Console.WriteLine($"str1和str2的地址:{object.ReferenceEquals(str1, str2)}");//true

            //Console.WriteLine($"str1和str5的equel:{str1.Equals(str5)}");//true
            //Console.WriteLine($"str1和str5的地址:{object.ReferenceEquals(str1, str5)}");//false

            //ReferenceEquals
            //值类型比较

            //int v1 = 1;
            //int v2 = 1;
            //double v3 = 1;

            //Console.WriteLine($"值类型的ReferenceEquals:{object.ReferenceEquals(v1, v2)}");//false
            //Console.WriteLine($"值类型的ReferenceEquals:{object.ReferenceEquals(v1, v3)}");//false

            //引用类型
            //Student student1 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};

            //Student student2 = new Student()
            //{
            //    ID = 1,
            //    Name = "aaa"
            //};

            //Console.WriteLine($"引用类型的ReferenceEquals:{object.ReferenceEquals(student1,student2)}");//false

            //Student student3 = student1;

            //Console.WriteLine($"引用类型的ReferenceEquals:{object.ReferenceEquals(student1, student3)}");//true

            //string类型
            string str1 = "Hello";
            string str2 = "Hello";

            string str3 = "He";
            string str4 = "llo";
            string str5 = str3 + str4;

            Console.WriteLine($"1和2的地址：{object.ReferenceEquals(str1, str2)}");//true
            Console.WriteLine($"1和5的地址：{object.ReferenceEquals(str1, str5)}");//false

            Console.ReadKey();
        }
    }
}
